package com.gitee.wsl.mathematics.geometry.d2.rect

import com.gitee.wsl.math.Math.TWO_PI
import com.gitee.wsl.mathematics.interpolator.ext.QUARTER
import com.gitee.wsl.mathematics.interpolator.ext.ratio
import com.gitee.wsl.mathematics.interpolator.ext.times
import com.gitee.wsl.unit.angle.AngleUnit

data class RoundRectangle(val rect: Rectangle, val corners: RectCorners) {

    companion object {
        private fun areaQuarter(radius: Double): Double = Arc_length(radius, AngleUnit.QUARTER)
        private fun areaComplementaryQuarter(radius: Double): Double = (radius * radius) - areaQuarter(radius)
        private fun Arc_length(radius: Double, angle: AngleUnit): Double = TWO_PI * radius * angle.ratio
    }

    val area: Double get() = rect.area - (
            areaComplementaryQuarter(corners.topLeft) +
                    areaComplementaryQuarter(corners.topRight) +
                    areaComplementaryQuarter(corners.bottomLeft) +
                    areaComplementaryQuarter(corners.bottomRight)
            )
}